package com.zzxx.mapper;

import com.zzxx.domain.Permission;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface PermissionMapper {

    @Select("select * from permission")
    List<Permission> findAll();

    @Select("select * from permission where id in " +
            "(select permissionId from role_permission where roleId = #{rid})")
    Permission findByRId(String rid);

    @Select("select * from permission where id not in(" +
            "select permissionId from role_permission where roleId = #{id})")
    List<Permission> findOtherPermissionsById(String id);

    @Insert("insert into role_permission(permissionId, roleId) values(#{permissionId}, #{roleId})")
    void addPermission(@Param("permissionId") String permissionId, @Param("roleId") String roleId);

    @Insert("insert into permission(id,permissionName,url) values(#{id}, #{permissionName}, #{url})")
    void add(Permission permission);
}
